/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = ldap_get_derefAliases.c                          */
/*  NOTE      =                                                    */
/*  DATE      = 2015/11/19 by geyh                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include <ldap/ldap_comm.h>
#include <ldap/ldap_core.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"
#include "apmtest_cunit.h"
#include "apmtest_comm.h"

#include "../../../src/module/ldap/config.h"


extern L7session_ldap_private* __ldap_private_create(void);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;
    L7session_ldap_private *p_st_private = NULL;

    p_st_private = __ldap_private_create();

    i_ret = apmtest_create_ct(&p_st_conn, ldap_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,(char *)"\x0a\x01\x00", 3);

    i_ret = ldap_get_derefAliases(p_st_data, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);

    bytebuff_free(&p_st_data);
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);
    ldap_session_destroy(p_st_private);
    return;

}


static void __case2(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;
    L7session_ldap_private *p_st_private = NULL;

    p_st_private = __ldap_private_create();

    i_ret = apmtest_create_ct(&p_st_conn, ldap_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,(char *)"\x0a\x01\x02", 3);

    i_ret = ldap_get_derefAliases(p_st_data, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);

    bytebuff_free(&p_st_data);
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);
    ldap_session_destroy(p_st_private);
    return;

}

static void __case3(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;
    L7session_ldap_private *p_st_private = NULL;

    p_st_private = __ldap_private_create();

    i_ret = apmtest_create_ct(&p_st_conn, ldap_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,(char *)"\x0a\x01\x04", 3);

    i_ret = ldap_get_derefAliases(p_st_data, p_st_body_data);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);

    bytebuff_free(&p_st_data);
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);
    ldap_session_destroy(p_st_private);
    return;

}

int add_suite_ldap_get_derefAliases(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" ldap_get_derefAliases()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);


    return FR_SUCC;

}
